//
//  NSString+Common.m
//  club
//
//  Created by zhuangyihang on 12/16/15.
//  Copyright © 2015 zhuangyihang. All rights reserved.
//

#import "NSString+Common.h"

@implementation NSString(Common)

- (CGFloat)getHeightWithWidth:(CGFloat)width withFont:(UIFont *)font{
    CGFloat height = MAXFLOAT;
    
    CGRect r = [self boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return r.size.height;
}

- (CGFloat)getHeightWithWidth:(CGFloat)width withFont:(UIFont *)font withMaxLine:(NSInteger)line{
    CGFloat lineHeight = font.lineHeight;
    
    CGFloat height = MAXFLOAT;
    if (line==0) {
        height = MAXFLOAT;
    }else{
        height = line * lineHeight;
    }
    
    CGRect r = [self boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return r.size.height;
}

@end
